using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FoodController : MonoBehaviour
{
    private Rigidbody foodRb;
    public float force;
    public int score;

    private GameManager gameManager;
    public int num;

    // Start is called before the first frame update
    void Start()
    {
        foodRb = GetComponent<Rigidbody>();
        foodRb.AddForce(RandomForce(), ForceMode.Impulse);
        foodRb.AddTorque(RandomTorque(), RandomTorque(), RandomTorque(), ForceMode.Impulse);
        gameManager = GameObject.Find("GameManager").GetComponent<GameManager>(); 
    }

    Vector3 RandomForce()
    {
        return Vector3.up * Random.Range(7, 16);
    }

    float RandomTorque()
    {
        return Random.Range(-10f, 10f);
    }
    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnTriggerEnter(Collider other)
    {
        
       if(!gameObject.CompareTag("Bad"))
        {
            gameManager.stop = true;
        }
       else
        {
            Destroy(gameObject);
        }
    }

    private void OnMouseDown()
    {
        Destroy(gameObject);
        gameManager.UpdateScore(score);
        gameManager.SpawnParticle(num, transform.position, transform.rotation).Play();
    }
}
